package notRelevantAnymore;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import core.Group;



import db.DB_SQL;
import db.DB_Tools;
import parsing.Category;
import parsing.User;

public class CreateUserTable {

	
	
	
	/*
	 * when we move it to DB_SQL change to one argument ( without
	 * PreparedStatement or mySQL) change to non static function
	 * 
	 */

	public static int addNewUser(User newUser, PreparedStatement pstm) {
		try {
			pstm.setString(1, newUser.getName());
			pstm.setString(2, newUser.getPassword());
			pstm.addBatch();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}

		return 1;
	}

	public static int addNewCategory(Category newCategory,
			PreparedStatement pstm) {
		try {
			pstm.setString(1, newCategory.getCategoryName());
			pstm.addBatch();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}

		return 1;
	}

	public static int addNewGroup(Group newGroup, PreparedStatement pstm) {
		try {
			pstm.setString(1, newGroup.getName());
			pstm.addBatch();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}

		return 1;
	}
	
	public static void createUserTable(DB_SQL mySQL){
				Statement create = DB_Tools.String2Statements(
					statements.createTables.createUsersTable, mySQL.getStmt());

			if (mySQL.execStatment(create) == 0) {
				System.out.println("Query Failed");
			} else {
				System.out.println("Query Succeeded");
			}
		
	}
	
	public static void createGroupTable(DB_SQL mySQL){
		Statement create = DB_Tools.String2Statements(
			statements.createTables.createGroupTable, mySQL.getStmt());

	if (mySQL.execStatment(create) == 0) {
		System.out.println("Query Failed");
	} else {
		System.out.println("Query Succeeded");
	}

}

	
}
